package com.wzcl.app.utils;

import java.io.*;

/**
 * @author beingven
 * @Description TODO
 * @createTime 2020年12月18日 14:22:00
 */
public class StreamUtil {
    /**
     * 对象转InputStream
     * @param object 需要转换的对象
     * @return 返回InputStream
     * @throws IOException
     */
    public static InputStream objectToInputStream(Object object) throws IOException {
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
        objectOutputStream.writeObject(object);
        objectOutputStream.flush();
        objectOutputStream.close();
        return new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
    }

    /**
     * InputStream转BufferedReader
     * @param inputStream
     * @return BufferedReader对象
     */
    public static BufferedReader inputStreamToBufferedReader(InputStream inputStream){
        return new BufferedReader(new InputStreamReader(inputStream));
    }
}
